<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class PasswordRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'oldpassword' => 'required',
            'password'    => 'required|min:6|regex:/(?!^\d+$)(?!^[a-zA-Z]+$)[0-9a-zA-Z]{6,20}/|confirmed:password_confirmation',
        ];
    }

    public function messages()
    {
        return [
            'oldpassword.required'  =>  '原密码必填',
            'password.required'     =>  '新密码必填',
            'password.min'          =>  '密码至少6位',
            'password.regex'    =>  '密码必须包含数字和字母',
            'password.confirmed'    =>  '两次输入的密码不一致',
        ];
    }
}
